#ifndef _MAN_RGA_H_
#define _MAN_RGA_H_

#include <stdlib.h>
#include "im2d.hpp"
#include "RockchipRga.h"
#include "RgaUtils.h"
#include "rga.h"
#include "open3man/common.h"

/* 定义各个格式对用的像素所占数据位数 */

#define MANBGR 24	   //RGB
#define MANRGB 24	   
#define MANRGBA 32	   //RGBA
#define MANBGRA 32
#define MANNV12 12	   //420SP
#define MANNV21 12
#define MANYU12 12	   //420P
#define MANYV12 12
#define MANNV16 16	   //422SP
#define MANNV61 16	   
#define MANYU16 16	   //422P
#define MANYV16 16	   

#define MANROTA90 	90
#define MANROTA180	180
#define MANROTA270	270

/*
功能：用于存储 rga 接口申请的 drm buff
*/
struct ManRgaBuff {
	bo_t buff;
	int width;
	int height;
	int format;
	int fd;
	im_rect rect;
};

/*
功能：使用 RGA 2d 加速
方法：
	CreatBuff：创建 drm buff
	FreeBuff：释放 drm buff
	General：通用全能接口支持 copy、crop、rota、cvt、resize
	SetBuff：设置 buff
	Blend：双 buff 合成, srcB 是合成在上面的图片必须要有 A 分量
	
*/

class ManRga{
public:	
	ManRga();
	~ManRga();
	int CreatBuff(ManRgaBuff * buff);
	int FreeBuff(ManRgaBuff * buff);
	int General(ManRgaBuff * src,ManRgaBuff * dst,int rotation = 0,int rgacore = IM_SCHEDULER_RGA3_DEFAULT);
	void SetBuff(ManRgaBuff * buff,int W , int H, int format, int w = 0 , int h = 0 ,int x = 0 , int y = 0);
	int Blend(ManRgaBuff * srcA,ManRgaBuff * srcB,ManRgaBuff * dst = NULL , int rgacore = IM_SCHEDULER_RGA3_DEFAULT);
private:
	int ManIm2d(rga_buffer_t src, rga_buffer_t dst,int rotation, im_rect rsrc, im_rect rdst,int sync = 1, int *release_fence_fd = NULL);
	RockchipRga m_rkRga;
};

#endif
